<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <link rel="stylesheet" href="./animate.css"/>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 300px;
            top: 0px;
        }
        button{
            top: 200px;
            position: absolute;
        }
        .myname-enter{
            opacity: 0;
            left: 0px;
        }
        .myname-enter-active{
            transition: all 2s;
        }
        .myname-enter-to{
            opacity: 1;
            left: 300px;
        }
        .myname-leave{
            opacity: 1;
            left: 300px;
        }
        .myname-leave-active{
            transition: all 2s;
        }
        .myname-leave-to{
            opacity: 0;
            left: 600px;
        }
        .box2{
            width: 100px;
            height: 100px;
            background: blue;
        }
        .fade-enter{
            opacity: 0;
        }
        .fade-enter-active{
            transition: all 2s;
        }
        .fade-enter-to{
            opacity: 1;
        }

        .fade-leave{
            opacity: 1;
        }
        .fade-leave-active{
            transition: all 2s;
        }
        .fade-leave-to{
            opacity: 0;
        }

    </style>
</head>
<body>
    <div id="app">
        <transition name="myname">
            <!-- <div class="box" v-if="judge"></div> -->
        </transition>
        <!-- <button @click="showorhide">点击我显示隐藏</button> -->
        <!-- 默认会执行css动画 ，也可以用js事件钩子 ，禁止vue做css动画检测 -->
        <!-- <transition 
        :css="false"
        @before-enter="beforeEnter"
        @enter="enter"
        @leave="leave"
        >
            <div class="box2" v-if="judge2"></div>
        </transition>
        
        <button @click="showorhide2">点击我显示隐藏</button> -->
        <hr>
        <transition name="fade" mode="out-in">
            <div :is="comName"></div>
        </transition>
       
        <button @click="showorhide">点击我切换</button>
        <hr>
        <h1 :class="myclass">我是动画效果</h1>
        <button @click="addclass">点击我添加类名</button>
    </div>
    <template id="coma"> 
        <h1>我是aaaaaa组件</h1>
    </template>
    <template id="comb"> 
        <h1>我是bbbb组件</h1>
    </template>
    <script>
        // vue动画 ：一、css方式 二、js事件钩子 
        // 一、css方式：动画条件 是显示隐藏  : v-if v-show 组件切换
        // 二、js方式
        // 三、组件的切换
        let ComA = {
            template:"#coma"
        }

        let ComB = {
            template:"#comb"
        }



        new Vue({
            el:"#app",
            components:{
                ComA,
                ComB
            },
            data:{
                judge:true,
                judge2:true,
                comName:"com-a",
                myclass:""
            },
            methods:{
                showorhide(){
                    // this.judge = !this.judge;
                    if(this.comName=="com-a"){
                        this.comName = "com-b";
                    }else{
                        this.comName = "com-a";
                    }
                },

                showorhide2(){
                    this.judge2 = !this.judge2;
                },
                beforeEnter(el){
                    console.log("beforeEnter",el)
                    el.style.transition="all 1s";
                },
                enter(el,done){
                    console.log("enter");
                    el.style.opacity = 1;
                    // done ： 需要再动画执行完毕之后在执行
                    // done();
                    el.addEventListener("transitionend",done);
                    // e.addEventListener("transitionend",function(){
                    //     done();
                    // })
                },
                leave(el,done){
                    console.log("leave");
                    el.style.opacity = 0;
                    el.addEventListener("transitionend",done);
                    // done();
                },
                addclass(){
                    this.myclass = "animate__animated animate__flash";
                }
            }
        })

    </script>
</body>
</html>